package com.platform.controller.system;

import com.platform.common.annotation.Log;
import com.platform.common.core.controller.BaseController;
import com.platform.common.core.domain.AjaxResult;
import com.platform.common.core.domain.entity.SysUser;
import com.platform.common.core.page.TableDataInfo;
import com.platform.common.enums.BusinessType;
import com.platform.system.domain.dto.FileOperationDto;
import com.platform.system.domain.vo.FileOperationVo;
import com.platform.system.service.ISysFileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;

/**
 * @author Huangkai
 */
@RestController
@RequestMapping("/system/file")
public class FileController extends BaseController {
    @Autowired
    ISysFileService sysFileService;

    @Log(title = "文件上传", businessType = BusinessType.OTHER)
    @PostMapping("/upload")
    public AjaxResult upload(@RequestParam(value = "file") MultipartFile file){
        FileOperationDto fileOperationDto = sysFileService.importFile(file);
        return AjaxResult.success(fileOperationDto);
    }

    @Log(title = "查询平台的文件管理列表", businessType = BusinessType.OTHER)
    @GetMapping("/selectFileList")
    public TableDataInfo selectFileList(@Validated FileOperationVo fileOperationVo) {
        SysUser sysUser = getLoginUser().getUser();
        fileOperationVo.setTenantUid(sysUser.getTenantUid());
        return sysFileService.selectFileList(fileOperationVo);
    }
}
